package com.hzcx.app.simplechat.ui.moment.presenter;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.bean.UpLoadImgBean;
import com.hzcx.app.simplechat.model.MomentModel;
import com.hzcx.app.simplechat.model.PublicModel;
import com.hzcx.app.simplechat.model.UserModel;
import com.hzcx.app.simplechat.ui.moment.bean.MomentBean;
import com.hzcx.app.simplechat.ui.moment.bean.NewMessageCountBean;
import com.hzcx.app.simplechat.ui.moment.contract.MomentContract;
import com.hzcx.app.simplechat.ui.moment.contract.MomentCreateContract;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;
import com.hzcx.app.simplechat.util.file.FileUtils;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MomentPresenter extends BasePresenter<MomentContract.View> implements MomentContract.Presenter {


    /**
     *  获取动态列表
     * @param context
     * @param page
     */
    @Override
    public void getMomentList(Context context, int page) {
        MomentModel.getMomentList(context, page,null, new BaseObserver<List<MomentBean>>() {
            @Override
            protected void onSuccess(List<MomentBean> data) {
                mView.momentResult(data);
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                super.onFailure(e, errorMsg);
                mView.onFail();
            }
        });
    }

    /**
     *  上传图片
     * @param activity
     * @param url
     */
    @Override
    public void upLoadImg(Activity activity, String url) {
        PublicModel.upLoadImg(activity, TokenUtils.getTokenHeader(), url, new BaseDialogObserver<UpLoadImgBean>(activity) {
            @Override
            protected void onSuccess(UpLoadImgBean data) {
                mView.upLoadImgResult(data);
            }
        });
    }

    /**
     *  修改背景墙
     * @param context
     * @param url
     */
    @Override
    public void updateBackImg(Context context, String url) {
        UserModel.updateUserBackImg(context, url, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.updateBackImgSuccess(url);
            }
        });
    }

    /**
     *  点赞
     * @param context
     * @param id
     */
    @Override
    public void momentFabulous(Context context, int id,int pos) {
        MomentModel.momentFabulous(context, id, new BaseObserver<BaseEmptyBean>() {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.fabulousSuccess(pos);
            }
        });
    }

    /**
     *  删除动态
     * @param id
     */
    @Override
    public void deleteMoment(Context context,int id,int pos) {
        MomentModel.deleteMoment(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.deleteSuccess(pos);
            }
        });
    }

    /**
     *  获取新消息条数
     * @param context
     */
    @Override
    public void getNewMessageCount(Context context) {
        MomentModel.getNewMessageCount(context, new BaseObserver<NewMessageCountBean>() {
            @Override
            protected void onSuccess(NewMessageCountBean data) {
                mView.newMsgResult(data);
            }
        });
    }

    /**
     * 屏蔽动态
     *
     * @param context
     * @param id
     */
    @Override
    public void shieldMoment(Context context, int id,int pos) {
        MomentModel.shieldMoment(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.shieldSuccess(pos);
            }
        });
    }
}
